<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>
        峰思思专业租赁
    </title>

    <script src="js/jquery-2.2.3.min.js" type="text/javascript"></script>
    <script src="js/jquery-ui.min.js" type="text/javascript"></script>
    <link type="text/css" href="css/jquery-ui.min.css" rel="stylesheet">
    <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <script src="js/bootstrap.min.js" type="text/javascript"></script>
    <link type="text/css" href="css/login.css" rel="stylesheet">
    <link rel="shortcut icon" href="../resources/favicon.ico" th:href="@{/static/favicon.ico}"/>

    </head>
    <body>
		<header id="header">
			<img src="/img/loginjpg.jpg" width="20%" >
			<div class="a1"></div>
			<span class="a2">欢迎登陆</span><br>

		</header>

        <div id="center">
            <form name="myform" onsubmit="keyidenglu()" enctype="multipart/form-data" action="/doSelectUser" method="post" id="myform">
                <div class="input-group">
                    <h3 style="font-family: 楷体;">
                        用户名：
                    </h3>
					&nbsp;
					<input class="form-control" id="username" name="username" type="text" style="height:40px" value="" placeholder="只能输入字母或数字，4-16个字符" autocomplete="off">
                </div>
                <div class="input-group">
                    <h3 style="font-family: 楷体;">
                        密&nbsp;&nbsp;码：
                    </h3>
					&nbsp;
					<input class="form-control" id="password" name="password" type="password" style="height:40px" value="" placeholder="密码长度6-12位" autocomplete="off">

                </div>
                <div id=" btn" style="padding-top: 50px">
                    <a>
						<input class="btn btn-primary" name="loginButton" type="submit" id="login" value="登录">
					</a>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a href="javascript:doRegister()" target="_self">
						<input class="btn btn-primary" name="registerButton" id="register" type="button" value="注册">
					</a>
                </div>
            </form>
        </div>
        <script src="bower_components/jquery/dist/jquery.min.js"></script>

        <script type="text/javascript">
            $(function (){
                $("#login").click(doLogin)
                

            });


            function doLogin(){

                let params={

                    username:$("#username").val(),
                    password:$("#password").val(),
                };
                let url="doSelectUser";

                $.post(url,params,function(result){

                    if(result.state==1){

                        location.href="doIndexUI";
                    }else{
                        alert(result.message)
                        location.href="doLogin";
                    }
                    return false;//防止刷新时重复提交
                });
            }


			//验证信息
            function checkUserName() {    //验证用户名
                var fname = document.myform.username.value;
                var reg = /^[0-9a-zA-Z]/;
                if (fname.length != 0) {
                    for (i = 0; i < fname.length; i++) {
                        if (!reg.test(fname)) {
                            alert("只能输入字母或数字");
                            return false;
                        }
                    }
                    if (fname.length < 4 || fname.length > 16) {
                        alert("只能输入4-16个字符");
                        return false;
                    }
                }
                else {
                    alert("请输入用户名");
                    document.myform.username.focus();

                    return false;
                }
                return true;
            }

            function passCheck() { //验证密码
                var userpass = document.myform.password.value;
                if (userpass == "") {
                    alert("未输入密码 \n" + "请输入密码");
                    document.myform.password.focus();
                    return false;
                }
                if (userpass.length < 6 || userpass.length > 12) {
                    alert("密码必须在 6-12 个字符。\n");
                    return false;
                }
                return true;
            }
            function keyidenglu() {
                if (checkUserName() && passCheck() )
                    clearText();

                else
                    location.href="doLogin";
                return false;

            }


            function clearText() {
                document.myform.username.value = "";
                document.myform.password.value = "";

            }

            //点击注册
            function doRegister(){
                location.href=`/doRegister`
            }


		</script>
    </body>
</html>